package uniandes.comit.OIClient.back.interfaz;

import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;



public class PanelBancoRepublicaPeticion extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel labID = null;
	private JLabel labPassword = null;
	private JLabel labNombreUsuario = null;
	private JButton butExportar = null;
	private JTextField txtID = null;
	private JPasswordField txtPassword = null;
	private JTextField txtNombreUsuario = null;
	private InterfazBancoRepublica principal;
	/**
	 * This is the default constructor
	 * @param interfazBancoRepublica 
	 */
	public PanelBancoRepublicaPeticion(InterfazBancoRepublica nPrincipal) {
		super();
		principal = nPrincipal;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		labNombreUsuario = new JLabel();
		labNombreUsuario.setText("Id Banco de la Republica");
		labPassword = new JLabel();
		labPassword.setText("Nombre Usuario");
		labID = new JLabel();
		labID.setText("Password");
		GridLayout gridLayout = new GridLayout();
		gridLayout.setRows(4);
		gridLayout.setColumns(2);
		this.setLayout(gridLayout);
		this.setSize(350, 200);
		this.setEnabled(false);
		this.setBorder(BorderFactory.createTitledBorder(null, "Banco de La Republica", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
		this.add(labNombreUsuario, null);
		this.add(getTxtID(), null);
		this.add(labID, null);
		this.add(getTxtPassword(), null);
		this.add(labPassword, null);
		this.add(getTxtNombreUsuario(), null);
		this.add(getButExportar(), null);
	}

	/**
	 * This method initializes butExportar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getButExportar() {
		if (butExportar == null) {
			butExportar = new JButton();
			butExportar.setText("Exportar Planilla(s)");
			butExportar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					String id = txtID.getText();
					String nomUsuario = txtNombreUsuario.getText();
					char passArray[] = txtPassword.getPassword();
				    //AGUJERO DE SEGURIDAD CORREGIR!
					// Convertir el password a String
				    String password = new String(passArray);
					
					
					if(id.equals("")||password.equals(""))
					{
						JOptionPane.showMessageDialog(principal,"No se genero el archivo XSL","Campos Obligatorios Incompletos",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
						if(principal.generarXSL(id, password, nomUsuario ) == true)
						{
							String mensaje = JOptionPane.showInputDialog(null, "Tiempo X (en segundos)");
							if(mensaje==null||mensaje.equals(""))
							{
								JOptionPane.showMessageDialog(principal,"No se modifico el tiempo","Campo de ingres vacio",JOptionPane.INFORMATION_MESSAGE);
							}
							else
							{
								int tiempo = Integer.parseInt(mensaje);
								principal.tiempo(tiempo);
							}
						}
					}
				}
			});
		}
		return butExportar;
	}

	/**
	 * This method initializes txtID	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtID() {
		if (txtID == null) {
			txtID = new JTextField();
		}
		return txtID;
	}

	/**
	 * This method initializes txtPassword	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getTxtPassword() {
		if (txtPassword == null) {
			txtPassword = new JPasswordField();
		}
		return txtPassword;
	}

	/**
	 * This method initializes txtNombreUsuario	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtNombreUsuario() {
		if (txtNombreUsuario == null) {
			txtNombreUsuario = new JTextField();
		}
		return txtNombreUsuario;
	}

}
